package cc.vv.btpartyjob.homepage.activity

import android.support.v4.app.Fragment
import android.support.v4.view.ViewPager
import android.view.View
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.homepage.R
import cc.vv.btpartyjob.homepage.delegate.HomePageBaseBinder
import cc.vv.btpartyjob.homepage.delegate.LearnRankActivityDelegate
import cc.vv.btpartyjob.homepage.fragment.rank.MouthRankFragment
import cc.vv.btpartyjob.homepage.fragment.rank.ToTalRankFragment
import cc.vv.btpartyjob.jnimodule.adapter.JniViewPageAdapter
import cc.vv.mvp.activity.BaseActivityMVP
import cc.vv.mvp.binder.BaseDataBinder

/**
 * 学习排名
 * Created by Chen.qi on 2018/10/24.
 */
class LearnRankActivity : BaseActivityMVP<LearnRankActivityDelegate>() {
    /**
     * ViewPager适配器
     */
    private var mAdapter: JniViewPageAdapter? = null

    /**
     * Fragment集合
     */
    private var mFragments: ArrayList<Fragment>? = null


    override fun initData() {
        viewDelegate?.setTitleTopBar("学习排名")

        mFragments = ArrayList()
        val registerYesFragment = MouthRankFragment()
        val registerNoFragment = ToTalRankFragment()
        mFragments!!.add(registerYesFragment)
        mFragments!!.add(registerNoFragment)
        mAdapter = JniViewPageAdapter(supportFragmentManager, mFragments!!)
        viewDelegate?.setAdapterData(mAdapter!!)
        viewDelegate?.setBackGr(0)

    }

    override fun bindEvenListener() {
        viewDelegate?.setTitleBackBtnOnClick(object : BaseTopBarView.EventInterface {
            //返回
            override fun leftOnClick() {
                finish()
            }

            override fun leftCloseClick() {}
            override fun rightOnClick() {
            }
        })

        viewDelegate?.bindViewPagerLisener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {
            }

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
            }

            override fun onPageSelected(position: Int) {
                viewDelegate?.setBackGr(position)
            }

        })

        viewDelegate?.setOnClickListener(View.OnClickListener {
            viewDelegate?.setBackGr(0)
            viewDelegate?.setViewPagerPos(0)
        }, R.id.tv_alr_left)

        viewDelegate?.setOnClickListener(View.OnClickListener {
            viewDelegate?.setBackGr(1)
            viewDelegate?.setViewPagerPos(1)
        }, R.id.tv_alr_right)
    }

    override fun getDelegateClass(): Class<LearnRankActivityDelegate> {
        return LearnRankActivityDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return HomePageBaseBinder()
    }

}